using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SLNGP.Core;
using SLNGP.Core.Run;
using SLNGP.Core.Test;

namespace SLNGP.Test.CoreTests.Run
{
    [TestClass]
    [Tag("GeneticProgrammingRun")]
    public class GeneticProgrammingRun_Test : UnitTestBase<IGeneticProgrammingRun, GeneticProgrammingRun>
    {
        #region UnitTestBase methods
        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
            UnitTestBase<IGeneticProgrammingRun, GeneticProgrammingRun>.ClassInitialize(testContext);
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            UnitTestBase<IGeneticProgrammingRun, GeneticProgrammingRun>.ClassCleanup();
        }

        [TestInitialize]
        public override void TestInitialize()
        {
            base.TestInitialize();
        }

        [TestCleanup]
        public override void TestCleanup()
        {
            base.TestCleanup();
        }
        #endregion UnitTestBase methods

        [TestMethod]
        [ExpectedException(typeof(GeneticProgrammingException), "The number of parameters used for variables must be even. Pairs of variables names and variables values.")]
        public void Initialize_With1Argument_ExpectionIsThrownBecauseOfOddNumber()
        {
            // state - Initialize
            // action - WithOddArguments
            // Expectation - ExpectionIsThrown
            curElement.InitializeVariablesFromUntypedListOfObjects(new object[] { "X" });
        }

        [TestMethod]
        [ExpectedException(typeof(GeneticProgrammingException), "The number of parameters used for variables must be even. Pairs of variables names and variables values.")]
        public void Initialize_With3Arguments_ExpectionIsThrownBecauseOfOddNumber()
        {
            // state - Initialize
            // action - WithOddArguments
            // Expectation - ExpectionIsThrown
            curElement.InitializeVariablesFromUntypedListOfObjects(new object[] { "X", "Y", "Z" });
        }

        [TestMethod]
        public void Initialize_With4Parameters_HasTheCorrectVariablesCollection()
        {
            // state - Initialize
            // action - With4Parameters
            curElement.InitializeVariablesFromUntypedListOfObjects(new object[] { "X", TestInts[0], "Y", TestStrings[0] });



            // Expectation - HasTheCorrectVariablesCollection
            Assert.IsTrue(curElement.Variables.ContainsKey("X"));
            Assert.IsTrue((string)curElement.Variables["X"] == TestInts[0].ToString());
            Assert.IsTrue(curElement.Variables.ContainsKey("Y"));
            Assert.IsTrue((string)curElement.Variables["Y"] == TestStrings[0]);
        }
    }
}
